package com.yjhb.android.sbz.fragment;

import android.view.View;

import com.yjhb.android.sbz.adapter.FollowAdapter;
import com.yjhb.android.sbz.entity.Follow;
import com.yjhb.android.sbz.mvp.follow.FollowPresenter;
import com.yjhb.android.sbz.mvp.follow.FollowView;
import com.yjhb.android.sbz.tool.Tool;

import java.util.List;

/**
 * 创建者 zx
 * 创建时间 2020/11/19 9:47
 */
public class FollowFragment extends BaseListFragment<FollowPresenter, FollowAdapter, Follow> implements FollowView {
    private final String TAG = "FollowFragment";


    private int type; //1关注2粉丝

    @Override
    protected FollowAdapter getAdapter() {
        return new FollowAdapter(getContext(), type);
    }

    @Override
    protected void initUI() {
        super.initUI();
    }

    @Override
    protected CharSequence getTips() {
        return null;
    }

    @Override
    protected void onLoadData(int size, int current) {
        if (type == 1) {
            presenter.getSubscribe(current);
        } else if (type == 2) {
            presenter.getFans(current);
        }
    }

    @Override
    protected FollowPresenter initPresenter() {
        return new FollowPresenter(this);
    }

    @Override
    public void onItemClick(int index, Object o) {
        Follow follow = (Follow) o;
        Tool.startUserInfoActivity(getContext(), follow.getUserId());
    }

    @Override
    public void onViewClick(View view, String msg, int index, Object o) {
        Follow follow = (Follow) o;
        if (msg.equals("关注")) {
            presenter.cancelFollow(follow.getUserId());
        }
    }

    @Override
    public void onSuccess(List<Follow> data, boolean isLoad) {
        loadingDialog.cancel();
        smartRefreshLayout.finishLoadmore();
        smartRefreshLayout.finishRefresh();
        if (!isLoad) {
            dataSet.clear();
        }
        if (data != null) {
            dataSet.addAll(data);
        }
        adapter.notifyDataSetChanged();
    }

    @Override
    public void onWait(String tips) {
        loadingDialog.setTipsText(tips);
        loadingDialog.show();
    }

    @Override
    public void onCancelSuccess() {
        loadingDialog.cancel();
        onLoadData(size, current);
    }

    public int getType() {
        return type;
    }

    public void setType(int type) {
        this.type = type;
    }
}
